<?php
/****
* 社团用户的主页模块
*/
import('@.Model.Where.TimelineWhereMachine');
import('@.Model.Where.EventWhereMachine');
class GroupAction extends InitAction{
    protected function _initialize(){
        parent::_initialize();
    }
    public function id(){
        $uid= $_GET['uid'];
        if (is_null( $uid) ||$uid <=0) {
            $this->error("参数错误");
            return;
        }
        $gm= new GroupModel();
        $user= $gm->find($uid);
        $this->assign('user', $user);
        
        /*
        $r= $this->getTimeline($uid);
        $this->assign('timeline', $r);
        */
        
        $r= $this->getEvent($uid, 0,5);
        $this->assign('eventsCreated', $r);

        $am= new AccountModel();
        $isMyFriend= false;
        if ($uid != ($myid=$this->isLogged())) {
            if ($am->hasFriend($myid, $uid)) {
                $isMyFriend= true;
            }
        }
	$this->assign('isMyFriend', $isMyFriend);
	$sv = new Model();
	$save = $sv->query("select * from `notice_event`,( select `eid` from `notice_event_mark` where '{$uid}'=`notice_event_mark`.`uid` and `notice_event_mark`.`take`!=0) as `haha` where `notice_event`.`id`=`haha`.`eid`");
	$this->assign('mymark',$save);	
	
	$wish = $sv->query("select * from `notice_event`,( select `eid` from `notice_event_mark` where '{$uid}'=`notice_event_mark`.`uid` and `notice_event_mark`.`wish`!=0) as `mama` where `notice_event`.`id`=`mama`.`eid`");
    $this->assign('mywish',$wish);
	
	$revfriends= $am->getRevFriends($uid);
        $this->assign('revfriends', $revfriends);
        
        $this->display('index');
    }
    
    protected function getEvent($uid, $start=0, $limit=null){
        $m= new EventModel();
        $map= new EventWhereMachine();
        $map->author($uid);
        $m->where($map->get())->field(array('id', 'title', 'img', 'location', 'time_start', 'time_end'))->order('`id` DESC');
        if (! is_null($limit)){
            $m->limit($start.','.$limit);
        }
        return $m->order('stamp_created DESC')->select();
    }
    protected function getTimeline($uid){
        $m= new TimelineModel();
        $map= new TimelineWhereMachine();
        $map->uid($uid);
        return $m->where($map->get())->limit(5)->select();
    }
}
?>